<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 1.编写一个像 sum(a)(b) = a+b 这样工作的 sum 函数。

        function sum(a) {
            return function (b) {
                return a + b;
            }
        }
        console.log(sum(1)(-5));

        // 2.简化 sort 按字段排序
        // 有一组需要排序的对象
        let users = [
        { name: "John", age: 20, surname: "Johnson" },
        { name: "Pete", age: 18, surname: "Peterson" },
        { name: "Ann", age: 19, surname: "Hathaway" }
        ];

        function byField(standard) {
            return function (a, b) {
                return a[standard] > b[standard] ? 1 : -1;
            }
        }
        users.sort(byField('age'))
        console.log(users);
        users.sort(byField('name'))
        console.log(users);
    </script>
</body>
</html>